import json


class json_crud:
    # 读取json文件,返回list类型数据
    def get_json_kv(self, json_url):
        with open(json_url, 'r', encoding='utf-8') as fp:
            json_data = json.load(fp)
        return json_data

    # 返回dict类型数据
    def get_json_dict(self, json_url):
        with open(json_url, 'r', encoding='utf-8') as fp:
            json_data = json.loads(fp.read())
            json_dict = dict(json_data)
        return json_dict

    # 将数据写入json文件中
    def set_json(self, json_url, new_dict):
        with open(json_url, 'w', encoding='utf-8') as fp:
            json.dump(new_dict, fp)
